<?php
	include('secure_db.php');
	session_start();
	if(!isset($_SESSION['clientonline'])){
		header('Location: accueil.php');
	}	
	
	
	if(isset($_GET['name']))	{
	
		$chunks = explode('/', $_SESSION['favoritestore']);
		$size=sizeof($chunks);
		if($size!=0){
			$var='';
			$i=1;
			
			if( $size==1 and $chunks[0]==Secure::db($_GET['name'])){
				$var='';
			}
			else if($size==1 and $chunks[0]!=Secure::db($_GET['name'])){
				header('Location: client-myfavoritestore.php');
			}
			else if($size>=2 and $chunks[0]==Secure::db($_GET['name'])){
				$var=$chunks[1];
				$i=2;
			}
			else if($size>=2){
				$var=$chunks[0];
			}
			
			for($i;$i<$size;$i++){
				if($chunks[$i]!=Secure::db($_GET['name'])){
					$var=$var.'/'.$chunks[$i];
				}
			}
	
			include("connection_mysqli.php");
			
			$req=$connexion->prepare('UPDATE client SET favoritestore= ? WHERE login= ?');
			$req->bind_param("ss",$val1,$val2);
			$val1=$var;
			$val2=$_SESSION['login'];
			
			$_SESSION['favoritestore']=$val1;
			$result=$req->execute();
			
			header('Location: client-myfavoritestore.php');
		}
	}
	else{
		header('Location: accueil.php');
	}
							
?>

